package app.web.admin.service.impl;

import app.web.admin.domain.pojo.AdminOfRole;
import app.web.admin.mapper.AdminOfRoleMapper;
import app.web.admin.service.AdminOfRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户角色服务实现
 * @author feizns
 * @since 2025-04-09
 */
@Service
@RequiredArgsConstructor
public class AdminOfRoleServiceImpl implements AdminOfRoleService {

    /**
     * 用户角色 Mapper
     */
    private final AdminOfRoleMapper mapper;

    @Override
    public void resetRoleIdsToUser(List<Long> roleIds, Long userId) {
        //删除指定用户的角色列表
        mapper.deleteByUserId(userId);
        //给指定的用户添加角色列表
        mapper.insertBatch(roleIds.stream().map(roleId -> AdminOfRole.of(userId, roleId)).toList());
    }

    @Override
    public void deleteByUserId(Long userId) {
        //删除指定用户的角色列表
        mapper.deleteByUserId(userId);
    }

}
